package org.tloss.web.editor.projects;

import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.tloss.web.editor.Utils;

public class WebEditorBuilder extends IncrementalProjectBuilder {
	public static final String ID = "org.tloss.web.editor.projects.WebEditorBuilder";

	protected IProject[] build(int kind, Map<String, String> args,
			IProgressMonitor monitor) throws CoreException {
		if (kind == FULL_BUILD) {
			fullBuild(getProject(), monitor);
		} else {
			incrementalBuild(getProject(), monitor, getDelta(getProject()));
		}
		return null;
	}

	

	private void incrementalBuild(IProject project, IProgressMonitor monitor,
			IResourceDelta delta) throws CoreException {
		if (delta == null) {
			fullBuild(project, monitor);
		} else {
			Utils.logInfo("Doing an incremental build");
			delta.accept(new WebEditorVisitor(monitor));
		}
	}

	private void fullBuild(IProject project, IProgressMonitor monitor)
			throws CoreException {
		Utils.logInfo("Doing a full build");
		project.accept(new WebEditorVisitor(monitor), IResource.NONE);
	}

}
